package xixirupan.tmgp.tencent.com.vmeim.ui.beautycircle.presenter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;

import com.sch.rfview.AnimRFRecyclerView;
import com.sch.rfview.manager.AnimRFLinearLayoutManager;

import java.util.List;

import xixirupan.tmgp.tencent.com.vmeim.ui.beautycircle.model.EssenseBiz;
import xixirupan.tmgp.tencent.com.vmeim.ui.beautycircle.model.IBeautyCircle;

/**
 * Created by lenovo on 2016/10/20.
 */

public class EssensePresenter {
    Context context;
    AnimRFRecyclerView recyclerView;
    LayoutInflater inflater;
    EssenseRecyAdapter adapter;
    EssenseBiz biz =new EssenseBiz();
    int pageSize,pagerNo;
   public void   initRecycler(int pageSize,int pagerNo)
    {
        this.pageSize =pageSize;
        this.pagerNo =pagerNo;
        biz.getData(new IBeautyCircle() {
            @Override
            public void postEssenseData(List<Object> _lists) {
                AnimRFLinearLayoutManager manager =new AnimRFLinearLayoutManager(context, AnimRFLinearLayoutManager.VERTICAL,false);
                recyclerView.setLayoutManager(manager);
                //
                Log.i("输出精华部分的数据源","------------->"+_lists.size());
                adapter =new EssenseRecyAdapter(_lists,context,inflater);
                recyclerView.setAdapter(adapter);
            }
        },pageSize,pagerNo);

    }
    public  void reloadData()
    {
        recyclerView.setLoadDataListener(new AnimRFRecyclerView.LoadDataListener() {
            @Override
            public void onRefresh() {
                pagerNo =1;
                pageSize=20;
                biz.getData(new IBeautyCircle() {
                    @Override
                    public void postEssenseData(List<Object> _lists) {
//                        AnimRFLinearLayoutManager manager =new   AnimRFLinearLayoutManager(context, AnimRFLinearLayoutManager.VERTICAL,false);
//                        recyclerView.setLayoutManager(manager);
//                        //
//                        Log.i("输出精华部分的数据源","------------->"+_lists.size());
//                        adapter =new EssenseRecyAdapter(_lists,context,inflater);
//                        recyclerView.setAdapter(adapter);
                         adapter.reloadListView(_lists,true);
                    }
                },pageSize,pagerNo);
                //数据加载完成
                recyclerView.refreshComplate();
            }

            @Override
            public void onLoadMore() {
             pagerNo ++;
                pageSize +=20;
                biz.getData(new IBeautyCircle() {
                    @Override
                    public void postEssenseData(List<Object> _lists) {
//                        AnimRFLinearLayoutManager manager =new    AnimRFLinearLayoutManager(context, AnimRFLinearLayoutManager.VERTICAL,false);
//                        recyclerView.setLayoutManager(manager);
//
//                        Log.i("输出精华部分的数据源","------------->"+_lists.size());
//                        adapter =new EssenseRecyAdapter(_lists,context,inflater);
                        recyclerView.setAdapter(adapter);
                        adapter.reloadListView(_lists,false);
                    }
                },pageSize,pagerNo);
                //加载更多数据
                recyclerView.loadMoreComplate();

            }
        });
    }
    public EssensePresenter (AnimRFRecyclerView recyclerView, Context context, LayoutInflater inflater)
    {
        this.recyclerView =recyclerView;
        this.context =context;
        this.inflater =inflater;
    }

}
